package a04持久化;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;
import util.RabbitMqUtils;

import java.util.Scanner;

/**
 * @Author forsake
 * @Description
 * 之前声明的队列不是持久化的队列，rabbitMQ重启后队列消失，队列持久化后也需要把消息持久化
 *
 * @Date 16:29 2022/12/10
 **/  
public class DurableTest {
    private static final String TASK_QUEUE_NAME = "durable_queue";

    public static void main(String[] argv) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        // 第二个参数为durable
        channel.queueDeclare(TASK_QUEUE_NAME, true, false, false,
                null);
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入信息");
        while (sc.hasNext()) {
            String message = sc.nextLine();
            // 持久化消息MessageProperties.PERSISTENT_TEXT_PLAIN
            channel.basicPublish("", TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes("UTF-8"));
            System.out.println("生产者发出消息" + message);

        }
    }
}
